<%-- 
    Document   : daocy
    Created on : 2014/2/24, 下午 02:02:00
    Author     : Gjun
--%>

<%@page import="java.util.HashMap"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%    
    String pag= request.getParameter("pag");
    if((pag==null)||(pag==""))
    {
        pag="1";
    }
    String sql="select * from 產品維護 ";
    String sql2="select COUNT(*)  AS COUNT from 產品維護 ";
    ArrayList<HashMap> rsList2=new db.DAO().query(sql2, new String[]{}) ;
    HashMap tempmap=rsList2.get(0);
    int temp=Integer.parseInt((String)tempmap.get("COUNT"));
    int allpage=temp%3==0?temp/3:((temp/3)+1);
    db.DAO dao=new db.DAO();
    ArrayList<HashMap> rsList=dao.query2(sql,new String[]{},pag);
    %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
          
        
            
                                     
        <%
    if(session.getAttribute("user")!=null)
    {
        out.print(session.getAttribute("user")+"  您好!!");
        out.print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<form action='login.jsp'>");
        out.print("<input type='submit' value='登出'>");         
        out.print("</form>");
    }else
    {
        out.print("尚未登入");
        out.print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<form action='login.jsp'>");
         out.print("<input type='submit' value='登入'>");         
         out.print("</form>");
    }
    %>
    <table border="1"><tr>
    <%
     
     for(int i=0;i<rsList.size();i++)
     {
        
         HashMap map =rsList.get(i);
       out.print("<td align='center'><a href=\"comm.jsp?id="+map.get("id")+"&pag="+pag+"\">");
       out.print("<img src=\"productPic\\"+map.get("id")+".png\" width=\"200\" height=\"200\"><br>");
        out.print(map.get("產品名稱")+"&nbsp&nbsp&nbsp&nbsp&nbsp$"+map.get("產品價格")+"</a></td>");
           
    
            }
     
     %>
        </tr><tr><td colspan="3" align="center"> 
     <a href=<%= response.encodeRedirectURL("daocy.jsp?pag="+(pag.equals("1")?1:Integer.valueOf(pag)-1))%>> 上一頁</a>
   <select id="x" onchange="Change()">
 <% 
     for(int i=0;i<allpage;i++){
         if(pag.equals(String.valueOf((i+1))))
         {
         out.print(" <option value=\""+(i+1)+"\" selected=\"selected\">第"+(i+1)+"頁</option>");
         }else{
              out.print(" <option value=\""+(i+1)+"\">第"+(i+1)+"頁</option>");
         }
         
     }
     %>     
 </select>
 <a href=<%= response.encodeRedirectURL("daocy.jsp?pag="+(pag.equals(allpage+"")?allpage:Integer.valueOf(pag)+1))%>> 下一頁</a>
 </td>
 </tr>
 </table>
  <form id="go" action=<%= response.encodeRedirectURL("daocy.jsp")%> method="post">    
     <input type="hidden" id="pag" name="pag" value="">
     
 </form>
     <form action="add.jsp">
         <input type="submit" value="我的購物車">
         <input type="hidden"  name="pag" value="1">
     </form>
     
 
 <script>
     function Change()
     {
        
         document.getElementById("pag").value=document.getElementById("x").value;
          
         document.getElementById("go").submit();
      
     }
 </script>
    </body>
</html>
